<template>
    <div class="body_background" :style="GetWindowBackground">
        <!--搜索框-->
        <div class="search-box">
            <div class="search-input-box">
                <img src="../../assets/img/search.png" class="search-img">
                <input class="keyword main-color small-font-size" placeholder="请输入发货单、订单号或产品名称" v-model="keyword">
            </div>
            <mt-button class="background white-color" size="small" @click="getKeywordFun">搜索</mt-button>
        </div>
        <div class="body_background">
            <ul class="top-nav-box">
                <li v-for="(item,index) in navList" :key="item.id"
                    @click="navClickFun(index)"
                >
                    <div class="type-name">
                        {{item.name}}
                        <i :class="index==1?'display-block':'display-none'" class="circular"></i>
                    </div>
                    <div :class="typeIndex==index?'active':'no_active'">&nbsp;</div>
                </li>
            </ul>
            <ul class="order-list-box">
                <li>
                    <router-link to="/GoodsDeliveryDetail?id=1&name='张三'">
                        <div class="order-top-box main-color middle-font-size">
                            <div>发货单号：1321313</div>
                            <div>待支付</div>
                        </div>
                        <div class="type small-font-size three-color">总部直供</div>
                        <div class="order-content-box" v-for="(item,index) in goodsObj.item" :key="item.id">
                            <img :src="item.imgUrl"/>
                            <div class="order-info-box">
                                <div class="main-color big-font-size">{{item.id}}--{{item.title}}</div>
                                <div class="three-color small-font-size">订单号：254545</div>
                                <div class="second-color small-font-size">X 12 (4箱)</div>
                            </div>
                        </div>
                    </router-link>
                    <!--更多-->
                    <div :class="goodsObj.show==true?'display-block':'display-none'">
                        <div class="order-content-box"
                             v-for="(item,index) in goodsObj.more"
                             :key="item.id"
                        >
                            <img :src="item.imgUrl"/>
                            <div class="order-info-box">
                                <div class="main-color big-font-size">{{item.id}}--{{item.title}}</div>
                                <div class="three-color small-font-size">订单号：254545</div>
                                <div class="second-color small-font-size">X 12 (4箱)</div>
                            </div>
                        </div>
                    </div>
                    <div class="more-box" @click="lookMoreOrder">
                        <div class="main-color small-font-size">查看更多</div>
                        <img src="../../assets/img/arrow.png" :class="goodsObj.show==true?'active-up':''">
                    </div>
                    <div class="small-font-size three-color order-item-price">共3件商品</div>
                    <div class="order-operation-box">
                        <div class="small-font-size second-color">发货时间：2021-05-08 12:12:12</div>
                    </div>
                </li>
            </ul>
            <div class="seize-seat light-color">-- 没有数据了 --</div>
        </div>
    </div>
</template>

<script>
    import {Toast, Button} from 'mint-ui';

    export default {
        name: "GoodsDeliveryList",
        data() {
            return {
                navList: [
                    {
                        id: 1,
                        name: '全部'
                    }, {
                        id: 2,
                        name: '待发货'
                    }, {
                        id: 3,
                        name: '已发货'
                    }, {
                        id: 4,
                        name: '已完成'
                    }],
                typeIndex: 0,//顶部类型索引
                keyword:'',
                GetWindowBackground: {
                    'min-height': ''
                },
                orderLen: 3,
                goodsList: [
                    {
                        id: 1,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }, {
                        id: 2,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }, {
                        id: 3,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }, {
                        id: 4,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }, {
                        id: 5,
                        title: "秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        num: 0,
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }
                ],
                goodsObj: {},
            }
        },
        mounted() {
            this.goodsNewArray();
        },
        methods: {
            //搜索
            getKeywordFun() {
                let keyword = this.keyword;
                console.log(keyword)
            },
            //重组数组
            goodsNewArray() {
                var old_arr = this.goodsList;
                var new_obj = {};
                var arr = []
                var more = []
                if (old_arr.length < 2) {
                    arr = old_arr
                } else {
                    for (var i = 0; i < old_arr.length; i++) {
                        var item = old_arr[i]
                        if (i < 2) {
                            arr.push({
                                id: item.id,
                                title: item.title,
                                imgUrl: item.imgUrl
                            })
                        } else {
                            more.push({
                                id: item.id,
                                title: item.title,
                                imgUrl: item.imgUrl
                            })
                        }
                    }
                }
                new_obj.item = arr;
                new_obj.more = more;
                new_obj.show = false;
                console.log(new_obj)
                this.goodsObj = new_obj
            },
            //顶部导航切换
            navClickFun(index) {
                this.typeIndex = index
            },
            //查看更多订单
            lookMoreOrder(item) {
                this.goodsObj.show = !this.goodsObj.show
            },
            //取消
            cancelClickFun() {
                Toast('取消');
            },
            //支付
            payClickFun() {
                Toast('支付');
            },
            getHeight() {
                // 获取浏览器高度，减去顶部搜索栏和导航栏的值 55 + 50（可动态获取）,再减去底部高度值60
                this.GetWindowBackground['min-height'] = window.innerHeight + 'px'
            },
        },
        // 生命周期 - 创建完成（可以访问当前this实例）
        created() {
            window.addEventListener('resize', this.getHeight) // 注册监听器
            this.getHeight() // 页面创建时先调用一次
        },
        // 生命周期 - 销毁完成
        destroyed() {
            window.removeEventListener('resize', this.getHeight)
        },
    }
</script>

<style lang="scss" scoped>

    .search-box {
        width: calc(100% - 40px);
        height: 35px;
        margin: auto;
        padding: 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: #fff;
        .search-input-box {
            width:80%;
            height: 35px;
            border-radius: 6px;
            background: #f8f7fc;
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }
        .search-img {
            width: 16px;
            height: 16px;
            margin-left: 10px;
        }
        .keyword {
            width: calc(100% - 20px);
            font-size: 14px;
            padding: 5px 10px;
            background: transparent;
            border: none;
            outline: none;
            list-style: none;
        }

    }

    .top-nav-box {
        width: 100%;
        height: 40px;
        overflow-x: auto;
        display: flex;
        padding-top: 5px;
        background: #fff;
        li {
            width: 25%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            font-size: 15px;
            .type-name {
                position: relative;
            }
            .circular {
                width: 8px;
                height: 8px;
                background: #05c569;
                border-radius: 50%;
                position: absolute;
                top: -5px;
                right: -5px;
            }
        }
        .no_active {
            width: 15px;
            height: 2px;
            margin-top: 3px;
            background: #fff;
        }
        .active {
            width: 15px;
            height: 2px;
            margin-top: 3px;
            background: #05c569;
        }
    }

    .order-list-box {
        width: calc(100% - 30px);
        height: auto;
        margin: 20px 15px 0 15px;
        li {
            width: calc(100% - 30px);
            background: #fff;
            padding: 0 15px;
            margin-bottom: 10px;
            border-radius: 4px;
            .type {
                width: 100%;
                text-align: left;
                padding-bottom: 5px;
            }
            .order-top-box {
                width: 100%;
                height: 35px;
                display: flex;
                justify-content: space-between;
                align-items: center;
            }
            .order-content-box {
                width: 100%;
                display: flex;
                padding: 7px 0;
                img {
                    width: 60px;
                    height: 60px;
                    margin-right: 10px;
                    border-radius: 1px;
                }
                .order-info-box {
                    width: calc(100% - 80px);
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    text-align: left;
                }
                .goods-count {
                    margin-top: auto;
                    margin-left: auto;
                }

            }
            .more-box {
                width: 100%;
                text-align: left;
                display: flex;
                align-items: center;
                margin: 8px 0;
                img {
                    width: 10px;
                    height: 6px;
                    margin: 0 5px;
                }
                .active-up {
                    transform: rotate(180deg);
                    -webkit-transform: rotate(180deg);
                    -moz-transform: rotate(180deg);
                }
            }
            .order-operation-box {
                width: 100%;
                height: 45px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                border-top: 1px dashed #D2D6DC;
                margin-top: 5px;
            }
            .order-item-price {
                width: 100%;
                display: block;
                text-align: right;
                margin-bottom: 10px;
            }
        }
    }

    .mint-button--primary.is-plain {
        border: 1px solid #b1b5d9;
        background-color: transparent;
        color: #b1b5d9;
        margin-left: 8px;
    }

    .mint-button--small {
        display: inline-block;
        padding: 0 10px;
        height: 31px !important;
    }


</style>